package com.zrrd.thread._08_pool;

import java.util.concurrent.*;

/**
 * @author WanJl
 * @version 1.0
 * @title MyThreadPoolDemo03
 * @description
 * @create 2023/10/29 17:06
 */
public class MyThreadPoolDemo03 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                2,
                5,
                2,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
        //获取线程
        Future<String> future = pool.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                String name = Thread.currentThread().getName();
                for (int i = 0; i < 10; i++) {
                    System.out.println(name + "---" + i);
                }
                return "线程" + name + "执行结束...";
            }
        });
        String s = future.get();
        System.out.println(s);

        //归还线程
        pool.shutdown();
    }
}
